package 哈尔滨理工大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HEBu {
    public static void main(String[] args) throws IOException {
        HEBuBean heBuBean = null;
        List<HEBuBean> heBuBeans = new ArrayList<>();
        String Url = "http://meec.hrbeu.edu.cn/2017/1010/c12756a292737/page.htm";
        Connection connect = Jsoup.connect(Url);
        Document post = connect.post();
//        System.out.println(post.text());
        Element ibox = post.getElementById("ibox");
        for (Element element : ibox.getElementsByTag("a")) {
            heBuBean = new HEBuBean();
            String text = element.text();//name
            heBuBean.setT_name(text);
//            System.out.println(text);
            Connection connect1 = Jsoup.connect(element.attr("href"));
            try {
                Document post1 = connect1.post();
                for (Element hLeft : post1.getElementsByClass("h_left")) {
                    System.out.println(hLeft.text());
                    heBuBean.setInfo(hLeft.text());
                }
            } catch (IOException e) {
//                throw new RuntimeException(e);
            }
            heBuBeans.add(heBuBean);
        }
        EasyExcel.write("src/HEBu.xlsx", HEBuBean.class).sheet("user").doWrite(heBuBeans);

    }
}
